-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip other sections when reading metadata #826
Conversation
@@ -126,11 +122,14 @@ func (r *reader) readTOC(toc *indexTOC) error { | |||
return err | |||
} | |||
|
|||
skipSection := len(tags) > 0 && !slices.Contains(tags, tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of introducing the "skip" concept, I could have taken advantage of the fact that the metadata sections are always first in the TOC. However, our index reading code is structured around flexible "section tags", and I got the feeling that section ordering wasn't an invariant we wanted to rely on.
@@ -169,6 +174,27 @@ func (r *reader) readTOC(toc *indexTOC) error { | |||
return nil | |||
} | |||
|
|||
func (r *reader) readHeader() (simpleSection, uint32, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I factored out the first part of readTOC
(now readTOCSections
). This wasn't critical for the change.
@@ -395,9 +421,9 @@ func (r *reader) readIndexData(toc *indexTOC) (*indexData, error) { | |||
return &d, nil | |||
} | |||
|
|||
func (r *reader) readMetadata(toc *indexTOC) ([]*Repository, *IndexMetadata, error) { | |||
func (r *reader) parseMetadata(metaData simpleSection, repoMetaData simpleSection) ([]*Repository, *IndexMetadata, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also simplified this method, as it's not a big deal to be copying simpleSection
. Not critical for the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice find!!!
2b05dff
to
508594e
Compare
508594e
to
d055f00
Compare
Tiny follow up to #826. I resolved a conflict incorrectly and reverted a log line improvement.
Looking at heap profiles, the
ReadMetadata
function creates a ton of garbage objects. The main contributor is in other sections from the TOC, specifically decodingcompoundSection.offsets
. However, to read metadata, we only really need to parse the metadata sections.This PR introduces a
skip
method that skips over a section without reading it. This greatly reduces the allocations fromReadMetadata
: